/**
 * @file   bufferguard.h
 * @Author Alexandre Chassany (alexandre.chassany@gmail.com)
 * @date   March 2011
 * @brief  Define an object to manipulate a buffer
 *
 * Poum-tchak is a free sound manipulation and synthesis, 
 * real-time and interactive music-clip rendering.
 *
 * Copyright (C) 2011  Chassany Alexandre and Gonzalez Antoine.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * he Free Software Foundation, either version 3 of the License, or
 * at your option) any later version.
 *
 * is program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef _ELIXIR_BUFFERGUARD_H_
#define _ELIXIR_BUFFERGUARD_H_

#include <renderer/ibufferbase.h>
#include <boost/shared_ptr.hpp>

namespace Elixir
{
  template<class T>
	class BufferGuard
  {
  public:
	BufferGuard(IBufferBase* buffer = NULL);

	T* lock(unsigned long offset = 0, unsigned long size = 0, unsigned long  flags = 0);
	void unlock();

	void fill(const T* data, std::size_t count);
	void release();

	const IBufferBase* getBuffer() const;
	unsigned long getCount() const;

  private:

	boost::shared_ptr<IBufferBase> buffer_;
  };

  #include "bufferguard-inl.h"
}

#endif // _ELIXIR_BUFFERGUARD_H_
